from mysql_in import mysql_sql_df
from mysql_in import mysql_to_sql

def dim_staff():
    # 用自定义的函数读取数据避免过多重复代码
    df_staff = mysql_sql_df('staff')

    # 删除["address_id",'picture','email']这5列无用数据
    df_staff.drop(labels=["address_id", 'picture', 'email', 'password', 'username'], axis=1, inplace=True)

    # 字段转换active（文档错误，正常是1转YES，0,转NO，其他转No）,zh是转换函数
    def zh(x):
        if x == '1':
            x = 'YES'
        elif x == 0:
            x = 'NO'
        else:
            x = 'No'
        return x

    # 转换
    df_staff['active'] = df_staff['active'].map(zh)

    mysql_to_sql(df_staff,'dim_staff')

